/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apt;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author PhiNguyen
 */
public class EmployeeTableModel extends AbstractTableModel {

    private ArrayList<String> colNames;
    private ArrayList<Employee> data;

    public EmployeeTableModel() {
    }

    public EmployeeTableModel(ArrayList colNames, ArrayList<Employee> data) {
        this.colNames = colNames;
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return colNames.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Employee e = data.get(rowIndex);

        if (columnIndex == 0) {
            return e.getId();
        }
        if (columnIndex == 1) {
            return e.getName();
        }
        if (columnIndex == 2) {
            return e.getbDay();
        }
        if (columnIndex == 3) {
            return e.getPhone();
        }
        return "";

    }

    @Override
    public String getColumnName(int column) {
        return colNames.get(column);
    }
    public Employee getEmployeeAtRow(int rowIndex){
        return data.get(rowIndex);
    }
    
}
